function Collapser(w, id, label) {
	this.w = w;
	this.id = id;

	this.w.controller.get(id).innerHTML = Mojo.View.render(
		{object: 
			{
				label: label,
				id: id
			}, 
		template: 'collapser'}
	);

	this.w.controller.listen(id+'_section', Mojo.Event.tap, this.handleDrawerSelection.bind(this));
}

Collapser.prototype.handleDrawerSelection = function(event) {
	var toggleButton = this.w.controller.get(this.id + '_toggle');	
	var folderContainer = this.w.controller.get(this.id + '_drawer');
		
	var showFavorites = toggleButton.hasClassName('palm-arrow-closed');
	var maxHeight = folderContainer.getHeight();
	
	if (showFavorites) {
		toggleButton.addClassName('palm-arrow-expanded');
		toggleButton.removeClassName('palm-arrow-closed');
		folderContainer.setStyle({ height:'0px' });
		folderContainer.show();
	} else {
		toggleButton.addClassName('palm-arrow-closed');
		toggleButton.removeClassName('palm-arrow-expanded');
		folderContainer.setStyle({ height: maxHeight + 'px' });
	}
	
	var options = {reverse: !showFavorites,
		onComplete: function(show, accountId, listHeight, folderContainer, cancelled) {
			if (cancelled) return;
			if (!show) {
				folderContainer.hide();
			}
			folderContainer.setStyle({height:'auto'});
		}.bind(this, showFavorites, this.id + '_target', maxHeight),
		curve: 'over-easy',
		from: 0,
		to: maxHeight,
		duration: 0.4};
		
	Mojo.Animation.animateStyle(folderContainer, 'height', 'bezier', options);
};

Collapser.prototype.setHTML = function(html) {
	this.w.controller.get(this.id + '_content').innerHTML = html;
};

Collapser.prototype.appendHTML = function(html) {
	this.w.controller.get(this.id + '_content').innerHTML += html;
};

Collapser.prototype.insert = function(e) {
	this.w.controller.get(this.id + '_content').insert(e);
};